package com.codi.fcloud.ufx.hssale.portfolio;

import com.codi.base.log.annotation.Loggable;
import com.codi.base.util.ExceptionUtil;
import com.codi.bus.exception.HundsunAPIException;
import com.codi.fcloud.ufx.HsUtil;
import com.codi.fcloud.ufx.UfxSDKFactory;
import com.codi.fcloud.ufx.constant.HSInputParameterNames;
import com.codi.fcloud.ufx.constant.UrlConstants;
import com.codi.trade.dto.HsCombTransferTradeDto;
import com.codi.trade.response.HsCombTransferTradeResponse;
import com.codi.trade.service.portfolio.HsCombTransferTradeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 模块名
 *
 * @author spy
 * @version 1.0 2018-01-30
 * @since 1.0
 */
@Slf4j
@Service
public class HsCombTransferServiceImpl extends UfxSDKFactory implements HsCombTransferTradeService {
    @Override
    protected String getTarget() {
        return UrlConstants.PREFIX_SALE + UrlConstants.COMB_TRANSFER_TRADE;
    }

    @Loggable
    @Override
    public Map<String, Object> transfer(HsCombTransferTradeDto dto) {

        String trustWay = apiValueMap.get(HSInputParameterNames.TRUST_WAY);
        Map<String, Object> request = new HashMap<>();

        request.put("trust_way", trustWay);//	C1	交易委托方式	Y
        request.put("net_no", getString(dto.getNet_no(), "0001"));//	C9	网点代码	N	不传则使用默认值"0001" ，有传值（包括空）则使用所传值
        request.put("trade_acco", getString(dto.getTrade_acco()));//	C17	交易账号	N
        request.put("ta_acco", getString(dto.getTa_acco()));//	C12	TA账号	N
        request.put("password", getString(dto.getPassword()));//	C50	密码	N	传加密后的密文,默认MD5(加密后密文是32位)加密方式
        request.put("apply_time", getString(dto.getApply_time()));//	C6	申请时间	N
        request.put("order_date", getString(dto.getOrder_date()));//	C8	下单日期	N
        request.put("portfolio_code", getString(dto.getPortfolio_code()));//	C4	投资组合编码	N
        request.put("transfer_mode", getString(dto.getTransfer_mode()));//	C1	调仓模式	N
        request.put("redeem_content", getString(dto.getRedeem_content()));//	C600	赎回内容	N
        request.put("communic_content", getString(dto.getCommunic_content()));//	C600	通讯内容	N
        request.put("capital_mode", getString(dto.getCapital_mode()));//	C2	资金方式	N
        request.put("detail_fund_way", getString(dto.getDetail_fund_way()));//	C2	明细资金方式	N
        request.put("broker", getString(dto.getBroker()));//	C8	经纪人	N
        request.put("trade_conduct_person", getString(dto.getTrade_conduct_person()));//	C20	交易经办人	N
        request.put("precheck_flag", getString(dto.getPrecheck_flag()));//	C1	预检查标识	N
        request.put("channel_serial_id", getString(dto.getChannel_serial_id()));//	C32	银商流水号	N
        request.put("check_no", getString(dto.getCheck_no()));//	C8	主管工号	N
        request.put("check_pwd", getString(dto.getCheck_pwd()));//	C50	主管密码	N
        request.put("proof_no", getString(dto.getProof_no()));//	C24	凭证编号	N


        try {
            Map<String, Object> response = getUfxSDK().transact(getTarget(), request);

            return appendLog(request, response);
        } catch (Exception exception) {
            ExceptionUtil.logError(logger, getTarget(), exception);
            throw new HundsunAPIException(ExceptionUtil.getMessage(exception));
        }
    }
}
